/*$.fn.ccayDifLog = function(module,objectId){

	//2 追加HTML
	this.ccayLoad("ccay/web/resource/common/componet/difLogContainer.html",function(){
		$("#view_logs_").bind('click',function(){
			//Ccay.Common.toggle($("#view_logs_"),'#view_logs_');
			Ccay.Component.DifLog.showHiddView(module,objectId);
		});
	});
	return this;
}*/
/**
 *@name Ccay.Component.DifLog
 *@description 差异日志控件.
 *
 *@since 2011-12-21
 *@param page 该参数为控制器对象的内部别名，方便控制器内部的调用。外部访问不到，外部只能通过Ccay.Component.DifLog访问其方法或属性
 */
Ccay.Module.define("Ccay.Component.DifLog",function(page,$S){
	
	/**
	 * @description 父容器对象,可以是普通dom对象，也可以是封装过的jquery对象。通过该容器去选择对象，可以避免因为页面有元素重名而导致的一些问题。
	 */	
	var  auditLogGrid,gridid;
	//全局参数.
	var module,objectId,options;
	var searchConditions = {};
	
	//isInitializeDifLogGrid是否已经加载了差异日志信息.
	var isInitializeDifLogGrid = false;
	/*
	 * 加载指定模块业务对象的差异日志.
	 * module:模块
	 * objectId:业务对象id
	 */
	page.showHiddView = function(module,objectId){
			//初始化日志Grid
			if(!isInitializeDifLogGrid){
				$("#difLogViewForm").ccayValidate();
				page.loadAuditLogs(module,objectId);
				isInitializeDifLogGrid = true;
			}
		};
	page.clearDifCondition = function (){ 
		$("#startDate_difflog").val("").valid();
		$("#endDate_difflog").val("").valid();
	};
	
	/**
	 * @description 加载模块的审计日志
	 * @param 
	 *	module : 模块，必传
	 *  objectid ：操作对象ID，必传
	 *  options ：其他参数,可选
	 */
	page.loadAuditLogs = function(pmodule,pobjectid){
		var gridOptions = {
				/*autoLoad:false,*/
				colsort:false, 
				percentWidth:true,
				columns : [
				  {field: 'timeStamp' , width:"20%",cssName:"center",header: $i18n("ccay.logs.label.timeStamp"),type:'datetime'},
				  {field: 'owner' , width:"20%",cssName:"center",header:$i18n("ccay.logs.label.userId"),content:"${#Ccay.Component.DifLog.ownerRender(data)}"},
				  {field: 'hostIP' , width:"15%",cssName:"center",header:$i18n("ccay.common.label.ipAddress")},
				  {field: 'operation' , width:"20%",header:$i18n("ccay.logs.label.operation")},
				  {field: 'timeStamp', header:$i18n("ccay.common.label.viewLogs"), width:"20%",content:"${#Ccay.Component.DifLog.difLogButton(timeStamp, data)}"}
				       ],
				fnBeforeRequest: function (op) {
					if(!$("#difLogViewForm").valid()){
						return false;
					}
					var URL = "services/ccay/logs/log/list/dif/page/{0}/{1}";
					if(Ccay.DataHelper.isEmpty(searchConditions.module) || Ccay.DataHelper.isEmpty(searchConditions.objectId)){
						Ccay.UI.topBox("ccay.support.error.parameter");
					}else{
						URL = URL.concat("?module={0}".formatURI(searchConditions.module));
						URL = URL.concat("&objectId={0}".formatURI(searchConditions.objectId));
						
						var startDate = $("#startDate_difflog").val();
						if(startDate){
						  URL = URL.concat("&startDate.time={0}".formatURI(startDate.toDate().getTime()));
						}
						var endDate = $("#endDate_difflog").val();
						if(endDate){
							URL = URL.concat("&endDate.time={0}".formatURI(endDate.toDate().getTime()));
						}
					}
				    op.ajax.url = URL;
				},
				ajax:{
                    url: "services/ccay/logs/log/list/dif/page/{0}/{1}"
                },	
				operation:{
				    search:{
				    	btn:'#btnSearchDifLog'
				    	//panel:'#difLogViewForm'
				    	//url:"services/ccay/logs/log/list/dif/page/{0}/{1}",
				    	//fnload:search
				    }
				 }
		}
		//赋值.
		searchConditions.module = pmodule;
		searchConditions.objectId = pobjectid;
		gridid = "#difLogGrid";
		$S(gridid).igrid(gridOptions);	
		//auditLogGrid.init();
	};

	/**
	 * @description  打开审计日志版本比较页面dialog
	 * @param 
	 */
	page.opendialog = function (timeStamp,module,objectId){
		var dialog="";
		var param = {timeStamp:Ccay.Format.toDate(timeStamp),module:module,objectId:objectId};
		var options={
					modal:true,
					top : 100,
					"width":610,
					callback:function(){
						Ccay.Component.ComparaLog.init(param,"compareLog");
					}
				};
		Ccay.Page.register("Ccay.Component.DifLog.CompareLog","ccay/web/resource/common/component/difLog/compareLog.html");
		dialog=Ccay.UI.dialog("Ccay.Component.DifLog.CompareLog","ccay.logs.label.compare",options);
	};
	
	page.difLogButton = function (value, record){
		return Ccay.UI.button("ccay.common.button.log","Ccay.Component.DifLog.opendialog('{0}','{1}','{2}')".formatValue(record.timeStamp.toDateTime().getTime(),record.module,record.objectId),
			   null,"img","log");
    }
    
    page.ownerRender = function (record){
    	return record.owner || record.userId;
    }
});


